<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>编辑</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>姓名</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>沟通人</label>
                        <div class="layui-input-block">
                            <input type="text" name="gouer" id="gouer" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>沟通性质</label>
                        <div class="layui-input-block">
                            <div id="gouxing"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>沟通日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="goudt" id="goudt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>起止时间</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="qizhi" id="qizhi" placeholder="请选择" autocomplete="off" class="layui-input bdate_sea_range_hi">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>本月沟通次数(含本次)</label>
                        <div class="layui-input-block">
                            <input type="number" name="gouci" id="gouci" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">本月沟通记录</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="pengids" class="layui-input pengids" onclick="openPage('../public/choose_peng.php?choose_type=checkbox&page=peng&dom=pengids','80%','80%')">
                            <div class="choose_div" id="pengids" key="0"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_peng.php?choose_type=checkbox&page=peng&dom=pengids','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">沟通内容</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>
        </div>

    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            name: {required: true},
            gouer: {required: true},
            qizhi: {required: true},
            gouci: {required: true},
            goudt: {required: true},
        },
        messages:{
            name: {required: "请输入"},
            gouer: {required: "请输入"},
            qizhi: {required: "请输入"},
            gouci: {required: "请输入"},
            goudt: {required: "请选择"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_peng_edit,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                var pengids_info = res.data.pengids_info;
                if(pengids_info){
                    for (var key in pengids_info){
                        set_choose_btn('pengids',pengids_info[key].id,pengids_info[key].sericnum);
                    }
                }




                $("#name").val(data.name);
                $("#gouer").val(data.gouer);
                $("#gouxing").val(data.gouxing);
                $("#goudt").val(data.goudt);
                $("#qizhi").val(data.qizhi);
                $("#gouci").val(data.gouci);
                $("#explain").val(data.explain);

                xmselect_dan('gouxing', res.data.gouxing, data.gouxing, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#gouxing").find('xm-select').removeClass('error');
                    }else{
                        $("#gouxing").find('xm-select').addClass('error');
                    }
                });

                initParseMoney();
                public_upload_file_load('upload_files', res.data.files);
                render_date();
                render_from();
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();

            data.field.pengids = get_choose_val('pengids');
            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();

                if(!data.field.gouxing){
                    $("#gouxing").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#gouxing").find('xm-select').removeClass('error');
                }


                if(!validRes){return false;}
            }


            data = parseMoney(data);
            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_peng_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });

</script>
</body>
</html>
